var RepairPlanTableInit = function () {
    var oTableInit = {};
    //初始化Table
    oTableInit.Init = function () {
        $('#repairPlanTable').bootstrapTable({
            url: ctx + '/equipment/repairPlan/findRepairPlanByPage/get.mvc',         //请求后台的URL（*）
            method: 'get',                      //请求方式（*）
//            toolbar: '#toolbar',                //工具按钮用哪个容器
            striped: true,                      //是否显示行间隔色
            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            pagination: true,                   //是否显示分页（*）
            paginationLoop: false,
            sortable: true,                     //是否启用排序
            sortOrder: "asc",                   //排序方式
            queryParams: oTableInit.queryParams,//传递参数（*）
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
            search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
            strictSearch: true,
            showColumns: false,                  //是否显示所有的列
            showRefresh: false,                  //是否显示刷新按钮
            minimumCountColumns: 2,             //最少允许的列数
            clickToSelect: true,                //是否启用点击选中行
            height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
            uniqueId: "pkId",                     //每一行的唯一标识，一般为主键列
            showToggle: false,                    //是否显示详细视图和列表视图的切换按钮
            cardView: false,                    //是否显示详细视图
            detailView: false,                   //是否显示父子表
            singleSelect: false,                    //禁止多选
            checkboxHeader: true,                 //列头取消多选
            /*fixedColumns: true,
            fixedNumber: 3,*/
            columns: [
                {
                    checkbox: true,
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '序号',
                    align: 'center',
                    valign: 'middle',
                    formatter: function (value, row, index) {
                        var options = $('#repairPlanTable').bootstrapTable('getOptions');
                        return options.pageSize * (options.pageNumber - 1) + index + 1;
                    }
                }, {
                    field: 'planDepartment',
                    title: '计划部门',
                    sortable: false,
                    align: 'center',
                    valign: 'middle'
                }, {
                    field: 'equipCode',
                    title: '设备编号',
                    sortable: false,
                    align: 'center',
                    valign: 'middle'
                }, {
                    field: 'equipName',
                    title: '设备名称',
                    sortable: false,
                    align: 'center',
                    valign: 'middle'
                }, {
                    field: 'maintenanceProject',
                    title: '检修项目',
                    sortable: false,
                    align: 'center',
                    valign: 'middle'
                }, {
                    field: 'maintenanceCategoryValue',
                    title: '检修类别',
                    sortable: false,
                    align: 'center',
                    valign: 'middle'
                }, {
                    field: 'readyFlag',
                    title: '工装备件准备情况',
                    sortable: false,
                    align: 'center',
                    valign: 'middle',
                    formatter: function (value, row, index) {
                        var str = '';
                        var toolList = row.toolList;
                        if (toolList) {
                            for (var i = 0; i < toolList.length; i++) {
                                str += toolList[i].toolName + ","
                            }
                        }
                        var partList = row.partList;
                        if (partList) {
                            for (var j = 0; j < partList.length; j++) {
                                str += partList[j].partName + ","
                            }
                        }
                        if (value === '1') {
                            str += "已准备"
                        } else {
                            str += "未准备"
                        }

                        return str;
                    }
                }, {
                    field: 'staffInput',
                    title: '计划工时数',
                    sortable: false,
                    align: 'center',
                    valign: 'middle'

                }, {
                    field: 'dutyDepartment',
                    title: '责任部门',
                    sortable: false,
                    align: 'center',
                    valign: 'middle'
                }, {
                    field: 'dutyUserName',
                    title: '责任人',
                    sortable: false,
                    align: 'center',
                    valign: 'middle'
                }, {
                    field: 'assistDepartment',
                    title: '协办部门',
                    sortable: false,
                    align: 'center',
                    valign: 'middle'
                }, {
                    field: 'assistUserName',
                    title: '协办人',
                    sortable: false,
                    align: 'center',
                    valign: 'middle'
                }, {
                    field: 'maintenanceStartDate',
                    title: '计划开始时间',
                    sortable: false,
                    align: 'center',
                    valign: 'middle'
                }, {
                    field: 'maintenanceEndDate',
                    title: '计划结束时间',
                    sortable: false,
                    align: 'center',
                    valign: 'middle'
                }, {
                    field: 'shutdownFlag',
                    title: '停产',
                    sortable: false,
                    align: 'center',
                    valign: 'middle',
                    formatter: function (value) {
                        if (value === '1') {
                            return "是"
                        } else {
                            return "否"
                        }
                    }
                }, {
                    field: 'effectArea',
                    title: '影响区域/设备',
                    sortable: false,
                    align: 'center',
                    valign: 'middle'
                }, /* {
                    field: 'remark',
                    title: '备注',
                    sortable: false,
                    align: 'center',
                    valign: 'middle'
                }, */{
                    field: 'pkId',
                    title: 'pkId',
                    visible: false
                }]

        });
    };
    //得到查询的参数
    oTableInit.queryParams = function (params) {
        return {   // 这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
            size: params.limit,   // 页面大小
            num: (params.offset / params.limit) + 1,  // 页码
            sort: params.sort,
            order: params.order,
            equipCode:$("#equipCodeQuerySelect2").find("option:selected").text(),
            equipName:$("#equipName").val(),
            maintenanceProject: $("#maintenanceProject").val(),
            dutyDepartment:$("#department").val(),
            maintenanceStartDate:$("#maintenanceStartDate").val(),
            maintenanceEndDate:$("#maintenanceEndDate").val()
        }
    };
    return oTableInit;
};

jQuery(document).ready(function () {
    //1.初始化Table
    var oTable = new RepairPlanTableInit();
    oTable.Init();
    //初始化页面
    repairPlanInit.init();
});


var repairPlanInit = function () {
    var dutyUserSelect2,
        assistUserSelect2,
        toolSelect2,
        partSelect2,
        equipSelect2;
    return {
        init: function () {
            repairPlanInit.getSysDict("MAINTENANCE_CATEGORY", "maintenance-category");
            repairPlanInit._initDateControl();
            repairPlanInit._modalHidden();
            repairPlanInit._query();
            repairPlanInit._keyQuery();
            repairPlanInit._refresh();
            repairPlanInit._reset();
            dutyUserSelect2 = repairPlanInit._initDutyUserSelect2();
            assistUserSelect2 = repairPlanInit._initAssistUserSelect2();
            toolSelect2 = repairPlanInit._initToolSelect2();
            partSelect2 = repairPlanInit._initPartSelect2();
            equipSelect2 = repairPlanInit._initEquipCodeSelect2();
            repairPlanInit._initEquipCodeQuerySelect2();
            repairPlanInit._add();
            repairPlanInit._save();
            repairPlanInit._update();
            repairPlanInit._delete();
            repairPlanInit._getEquipInfo();
            repairPlanInit._validatorForm();
            SystemCommon.changeShortcutTime();
        },
        getSysDict : function (parentKey,eleClass) {
            $.ajax({
                url: ctx +'/system/dict/getSysDictsByParentKey/get.mvc',
                type:"post",
                aysnc: true,
                dataType:'json',
                data : {
                    parentKey:parentKey
                },
                success : function(response){
                    if(response&&response.data) {
                        var _data = response.data;
                        for (var i = 0; i < _data.length; i++) {
                            $("."+eleClass).append("<option value='"+_data[i].dictKey+"' >" + _data[i].dictValue + "</option>");
                        }
                    }

                },
                error: function(XMLHttpRequest, textStatus, errorThrown){
                    console.log(errorThrown);
                    alert("系统错误");
                }
            });
        },
        //条件查询
        _query: function () {
            $("#queryShutdownPlan").on("click", function () {
                $('#repairPlanTable').bootstrapTable('refreshOptions', {
                    pageNumber: 1
                });
            });
        },
        //按键查询
        _keyQuery: function () {
            $(".shutdown-plan-query").keypress(function (e) {
                if (e.which === 13) {
                    $("#queryShutdownPlan").trigger("click");
                }
            });
        },
        //重置查询
        _reset: function () {
            $(".reset").on("click", function () {
                $(".clearfix input").val("");
                $("#equipCodeQuerySelect2").val(null).trigger("change");
                $("#shortcutTime").val("");
            });

        },
        _refresh: function () {
            //刷新
            $("#refreshTable").on("click", function () {
                $('#repairPlanTable').bootstrapTable('refresh');
            });
        },
        _initDateControl: function () {
            $('.form-datetime').datetimepicker({
                format: 'yyyy-mm-dd hh:ii:00',
                language: 'zh-CN',
                autoclose: true,
                pickerPosition: "bottom-left",
                forceParse: true
            }).on('hide', function (event) {
                event.preventDefault();
                event.stopPropagation();
            });
        },
        _initDutyUserSelect2: function () {
            var select2 = $('#dutyUserFormSelect2').select2({
                ajax: {
                    url: ctx + '/system/user/getSysUserList/get.mvc',
                    dataType: 'json',
                    aynsc: false,
                    data: function (params) {
                        // Query parameters will be ?search=[term]&page=[page]
                        return {
                            search: params.term,
                            page: params.page || 1,
                            size: 10
                        };
                    },
                    processResults: function (data) {
                        // Tranforms the top-level key of the response object from 'items' to 'results'
                        var test = [];
                        for (var int = 0; int < data.data.length; int++) {
                            var obj = {};
                            obj.id = data.data[int].username;
                            obj.text = data.data[int].truename;
                            test.push(obj);
                        }
                        return {
                            results: test
                        };
                    },
                    // Additional AJAX parameters go here; see the end of this chapter for the full code of this example
                    cache: true

                },
                placeholder: '请选择',
                language: "zh-CN",
                escapeMarkup: function (markup) {
                    return markup;
                }, // let our custom formatter work
                minimumInputLength: 0
            });
            return select2;
        },
        _initAssistUserSelect2: function () {
            var select2 = $('#assistUserFormSelect2').select2({
                ajax: {
                    url: ctx + '/system/user/getSysUserList/get.mvc',
                    dataType: 'json',
                    aynsc: false,
                    data: function (params) {
                        // Query parameters will be ?search=[term]&page=[page]
                        return {
                            search: params.term,
                            page: params.page || 1,
                            size: 10
                        };
                    },
                    processResults: function (data) {
                        // Tranforms the top-level key of the response object from 'items' to 'results'
                        var test = [];
                        for (var int = 0; int < data.data.length; int++) {
                            var obj = {};
                            obj.id = data.data[int].username;
                            obj.text = data.data[int].truename;
                            test.push(obj);
                        }
                        return {
                            results: test
                        };
                    },
                    // Additional AJAX parameters go here; see the end of this chapter for the full code of this example
                    cache: true

                },
                placeholder: '请选择',
                language: "zh-CN",
                escapeMarkup: function (markup) {
                    return markup;
                }, // let our custom formatter work
                minimumInputLength: 0
            });
            return select2;
        },
        _initToolSelect2: function () {
            var select2 = $('#toolSelect2').select2({
                ajax: {
                    url: ctx + '/tool/toolInfo/listToolInfoByFilter/get.mvc',
                    dataType: 'json',
                    data: function (params) {
                        // Query parameters will be ?search=[term]&page=[page]
                        return {
                            toolName: params.term,
                            num: params.page || 1,
                            size: 10
                        };
                    },
                    processResults: function (response, params) {
                        // Tranforms the top-level key of the response object from 'items' to 'results'
                        params.page = params.page || 1;
                        var test = [];
                        if (response.rows) {
                            var _data = response.rows;
                            for (var int = 0; int < _data.length; int++) {
                                var obj = {};
                                obj.id = _data[int].pkId;
                                obj.text = _data[int].toolName;
                                test.push(obj);
                            }
                        }
                        return {
                            results: test,
                            pagination: {
                                more: (params.page * 10) < response.total
                            }
                        };
                    },
                    // Additional AJAX parameters go here; see the end of this chapter for the full code of this example
                    cache: true

                },
                placeholder: '',
                language: "zh-CN",
                escapeMarkup: function (markup) {
                    return markup;
                }, // let our custom formatter work
                minimumInputLength: 0
            });
            return select2;
        },
        _initPartSelect2: function () {
            var select2 = $('#partSelect2').select2({
                ajax: {
                    url: ctx + '/equipment/repairPlan/findPartByPage/get.mvc',
                    dataType: 'json',
                    data: function (params) {
                        // Query parameters will be ?search=[term]&page=[page]
                        return {
                            search: params.term,
                            num: params.page || 1,
                            size: 10
                        };
                    },
                    processResults: function (response, params) {
                        // Tranforms the top-level key of the response object from 'items' to 'results'
                        params.page = params.page || 1;
                        var test = [];
                        if (response.rows) {
                            var _data = response.rows;
                            for (var int = 0; int < _data.length; int++) {
                                var obj = {};
                                obj.id = _data[int].pkId;
                                obj.text = _data[int].partName;
                                test.push(obj);
                            }
                        }
                        return {
                            results: test,
                            pagination: {
                                more: (params.page * 10) < response.total
                            }
                        };
                    },
                    // Additional AJAX parameters go here; see the end of this chapter for the full code of this example
                    cache: true

                },
                placeholder: '',
                language: "zh-CN",
                escapeMarkup: function (markup) {
                    return markup;
                }, // let our custom formatter work
                minimumInputLength: 0
            });
            return select2;
        },
        _initEquipCodeSelect2: function () {
            var select2 = $('#equipCode').select2({
                ajax: {
                    url: ctx + '/measureTool/measureToolInfo/getEquipmentList/get.mvc',
                    dataType: 'json',
                    data: function (params) {
                        // Query parameters will be ?search=[term]&page=[page]
                        return {
                            search: params.term,
                            page: params.page || 1,
                            size: 10
                        };
                    },
                    processResults: function (response) {
                        // Tranforms the top-level key of the response object from 'items' to 'results'
                        var test = [];
                        if (response.data) {
                            var _data = response.data;
                            for (var int = 0; int < _data.length; int++) {
                                var obj = {};
                                obj.id = _data[int].pkId;
                                obj.text = _data[int].equipCode;
                                test.push(obj);
                            }
                        }
                        return {
                            results: test
                        };
                    },
                    // Additional AJAX parameters go here; see the end of this chapter for the full code of this example
                    cache: true

                },
                placeholder: '请选择',
                language: "zh-CN",
                escapeMarkup: function (markup) {
                    return markup;
                }, // let our custom formatter work
                minimumInputLength: 0
            });
            return select2;
        },
        _initEquipCodeQuerySelect2: function () {
            $('#equipCodeQuerySelect2').select2({
                ajax: {
                    url: ctx + '/measureTool/measureToolInfo/getEquipmentList/get.mvc',
                    dataType: 'json',
                    data: function (params) {
                        // Query parameters will be ?search=[term]&page=[page]
                        return {
                            search: params.term,
                            page: params.page || 1,
                            size: 10
                        };
                    },
                    processResults: function (response) {
                        // Tranforms the top-level key of the response object from 'items' to 'results'
                        var test = [];
                        if (response.data) {
                            var _data = response.data;
                            for (var int = 0; int < _data.length; int++) {
                                var obj = {};
                                obj.id = _data[int].pkId;
                                obj.text = _data[int].equipCode;
                                test.push(obj);
                            }
                        }
                        return {
                            results: test
                        };
                    },
                    // Additional AJAX parameters go here; see the end of this chapter for the full code of this example
                    cache: true

                },
                placeholder: '请选择',
                language: "zh-CN",
                escapeMarkup: function (markup) {
                    return markup;
                }, // let our custom formatter work
                minimumInputLength: 0
            });
        },
        //表单校验
        _validatorForm: function () {
            $("#repairPlanForm").bootstrapValidator({
                message: 'This value is not valid',
                live: 'submitted',
                fields: {
                    /*验证*/
                    equipCode: {
                        message: '',
                        validators: {
                            notEmpty: {
                                message: '不能为空'
                            }
                        }
                    },
                    maintenanceProject: {
                        message: '',
                        validators: {
                            notEmpty: {
                                message: '不能为空'
                            },
                            stringLength: {
                                max: 20,
                                message: '不能超过20个字符'
                            }
                        }
                    },
                    planDepartment: {
                        message: '',
                        validators: {
                            stringLength: {
                                max: 20,
                                message: '不能超过20个字符'
                            }
                        }
                    },
                    dutyDepartment: {
                        message: '',
                        validators: {
                            stringLength: {
                                max: 20,
                                message: '不能超过20个字符'
                            }
                        }
                    },
                    assistDepartment: {
                        message: '',
                        validators: {
                            stringLength: {
                                max: 20,
                                message: '不能超过20个字符'
                            }
                        }
                    },
                    maintenanceStartDate: {
                        trigger:'change',
                        message: '',
                        validators: {
                            notEmpty: {
                                message: '不能为空'
                            }
                        }
                    },
                    maintenanceEndDate: {
                        trigger:'change',
                        message: '',
                        validators: {
                            notEmpty: {
                                message: '不能为空'
                            }
                        }
                    }
                }
            });
        },
        _add: function () {
            $("#add").on("click", function () {
                $("#repairPlanForm").find(".title").text("新增");
                $.fn.modal.Constructor.prototype.enforceFocus = function () {
                    $("#myModal select").focus();
                };
                $("#myModal").modal();
            });

        },
        _getEquipInfo : function () {
            $("#equipCode").on("change",function () {
                $.ajax({
                    url: ctx+"/equipment/repairPlan/fingEquipInfoByEquipCode/get.mvc",
                    type: "post",
                    dataType: "json",
                    data: {
                        equipCode:$("#equipCode").find("option:selected").text()
                    },
                    success :function(response) {
                        if (response.result === true) {
                            var _data = response.data;
                            if (!_data)
                                return;
                            $("#repairPlanForm").find("input[name=equipName]").val(_data.equipName);
                            $("#repairPlanForm").find("input[name=factoryName]").val(_data.factoryName);
                            $("#repairPlanForm").find("input[name=lineName]").val(_data.lineName);
                            $("#repairPlanForm").find("input[name=shopName]").val(_data.shopName);
                            $("#repairPlanForm").find("input[name=areaName]").val(_data.areaName);
                        } else {
                            DialogUtil.error(response.message);
                        }
                    },
                    error :function() {
                        DialogUtil.error("系统繁忙！");
                    }
                });
            });
        },
        _update: function () {
            $("#update").on("click", function (e) {
                e.preventDefault();
                $('#myModal .title').html("修改");
                var ids = $.map($('#repairPlanTable').bootstrapTable('getSelections'), function (row) {
                    return row.pkId;
                });
                if (ids.length !== 1) {
                    DialogUtil.warning("请选择一行修改");
                    return false;
                }
                //解决select2无法输入问题
                $.fn.modal.Constructor.prototype.enforceFocus = function () {
                    $("#myModal select").focus();
                };
                //加载信息
                $.ajax({
                    url: ctx + "/equipment/repairPlan/findRepairPlanById/get.mvc",
                    type: "post",
                    dataType: "json",
                    data: {
                        pkId: ids.toString()
                    },
                    success: function (response) {
                        console.log(response);
                        if (response.result === true && response.data) {
                            var _data = response.data;
                            $("#repairPlanForm").find("input[name=pkId]").val(_data.pkId);
                            $("#repairPlanForm").find("input[name=equipName]").val(_data.equipName);
                            $("#repairPlanForm").find("input[name=factoryName]").val(_data.factoryName);
                            $("#repairPlanForm").find("input[name=lineName]").val(_data.lineName);
                            $("#repairPlanForm").find("input[name=shopName]").val(_data.shopName);
                            $("#repairPlanForm").find("input[name=areaName]").val(_data.areaName);
                            $("#repairPlanForm").find("input[name=maintenanceProject]").val(_data.maintenanceProject);

                            $("#repairPlanForm").find("select[name=maintenanceCategory]").val(_data.maintenanceCategory);
                            $("#repairPlanForm").find("input[name=planDepartment]").val(_data.planDepartment);
                            if (_data.shutdownFlag === '1') {
                                $("#repairPlanForm").find("input:checkbox[name='shutdownFlag']").prop("checked", "checked");
                            }
                            if (_data.readyFlag === '1') {
                                $("#repairPlanForm").find("input:checkbox[name='readyFlag']").prop("checked", "checked");
                            }
                            $("#repairPlanForm").find("input[name=planDepartment]").val(_data.planDepartment);
                            $("#repairPlanForm").find("input[name=dutyDepartment]").val(_data.dutyDepartment);
                            $("#repairPlanForm").find("input[name=assistDepartment]").val(_data.assistDepartment);
                            $("#repairPlanForm").find("input[name=maintenanceStartDate]").val(_data.maintenanceStartDate);
                            $("#repairPlanForm").find("input[name=maintenanceEndDate]").val(_data.maintenanceEndDate);
                            $("#repairPlanForm").find("input[name=staffInput]").val(_data.staffInput);
                            $("#repairPlanForm").find("textarea[name=effectArea]").val(_data.effectArea);
                            $("#toolSelect2").val().toString();
                            $("#partSelect2").val().toString();

                            //初始化设备select2
                            var equipId = _data.equipId;
                            var equipCode = _data.equipCode;
                            if (equipId != null && equipCode != null) {
                                var option = new Option(equipCode, equipId, true, true);
                                equipSelect2.append(option);
                                equipSelect2.trigger("change");
                            }

                            //初始化责任人
                            var dutyUser = _data.dutyUser;
                            var dutyUserName = _data.dutyUserName;
                            if (dutyUser != null && dutyUserName != null) {
                                var option = new Option(dutyUserName, dutyUser, true, true);
                                dutyUserSelect2.append(option);
                                dutyUserSelect2.trigger("change");
                            }
                            //初始化协助人
                            var assistUser = _data.assistUser;
                            var assistUserName = _data.assistUserName;
                            if (assistUserName != null && assistUser != null) {
                                var option = new Option(assistUserName, assistUser, true, true);
                                assistUserSelect2.append(option);
                                assistUserSelect2.trigger("change");
                            }

                            var toolList = _data.toolList;
                            if (toolList) {
                                for (var i = 0; i < toolList.length; i++) {
                                    //初始化工装
                                    var toolId = toolList[i].pkId;
                                    var toolName = toolList[i].toolName;
                                    if (toolId != null && toolName != null) {
                                        var option = new Option(toolName, toolId, true, true);
                                        toolSelect2.append(option);
                                    }
                                }
                                toolSelect2.trigger("change");
                            }
                            var partList = _data.partList;
                            if (partList) {
                                for (var j = 0; j < partList.length; j++) {
                                    //初始化备件
                                    var partId = partList[j].pkId;
                                    var partName = partList[j].partName;
                                    if (partId != null && partName != null) {
                                        var option = new Option(partName, partId, true, true);
                                        partSelect2.append(option);
                                    }
                                }
                                partSelect2.trigger("change");
                            }

                            $('#myModal').modal();

                        } else {
                            DialogUtil.error(response.message);
                        }
                    },
                    error: function () {
                        DialogUtil.error("系统繁忙！");
                    }
                });

            });
        },
        _save: function () {
            $("#myModal .yes").on("click", function (e) {
                $("#myModal .yes").attr("disabled", true);
                e.preventDefault();
                $("#repairPlanForm").data("bootstrapValidator").validate();
                var flag = $("#repairPlanForm").data("bootstrapValidator").isValid();
                if(!flag){
                    $("#myModal .yes").attr("disabled",false);
                    //未通过验证
                    return false;
                }
                var entity = {};
                entity['pkId'] = $("#repairPlanForm").find("input[name=pkId]").val();
                entity['equipCode'] = $("#equipCode").find("option:selected").text();
                entity['maintenanceProject'] = $("#repairPlanForm").find("input[name=maintenanceProject]").val();
                entity['maintenanceCategory'] = $("#repairPlanForm").find("select[name=maintenanceCategory]").val();
                entity['planDepartment'] = $("#repairPlanForm").find("input[name=planDepartment]").val();
                entity['shutdownFlag'] = $("#repairPlanForm").find("input:checkbox[name='shutdownFlag']").is(":checked") ? "1" : "0";
                entity['readyFlag'] = $("#repairPlanForm").find("input:checkbox[name='readyFlag']").is(":checked") ? "1" : "0";
                entity['dutyDepartment'] = $("#repairPlanForm").find("input[name=dutyDepartment]").val();
                entity['dutyUser'] = $("#repairPlanForm").find("select[name=dutyUser]").val();
                entity['assistDepartment'] = $("#repairPlanForm").find("input[name=assistDepartment]").val();
                entity['assistUser'] = $("#repairPlanForm").find("select[name=assistUser]").val();
                entity['maintenanceStartDate'] = $("#repairPlanForm").find("input[name=maintenanceStartDate]").val();
                entity['maintenanceEndDate'] = $("#repairPlanForm").find("input[name=maintenanceEndDate]").val();
                entity['staffInput'] = $("#repairPlanForm").find("input[name=staffInput]").val();
                entity['effectArea'] = $("#repairPlanForm").find("textarea[name=effectArea]").val();
                entity['toolIds'] = $("#toolSelect2").val().toString();
                entity['partIds'] = $("#partSelect2").val().toString();
                console.log(entity);
                $.ajax({
                    url: ctx + '/equipment/repairPlan/saveOrUpdateRepairPlan/save.mvc',
                    type: "post",
                    dataType: 'json',
                    data: entity,
                    success: function (response) {
                        if (response.result === true) {
                            DialogUtil.ok("保存成功");
                            //取消
                            $('#myModal').modal('hide');
                            $('#repairPlanTable').bootstrapTable('refresh');
                        } else {
                            DialogUtil.error(response.message);
                        }
                        $("#myModal .yes").attr("disabled", false);

                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $("#myModal .yes").attr("disabled", false);
                        console.log(errorThrown);
                        DialogUtil.error("系统错误");
                    }
                });

            });
        },
        //删除
        _delete: function () {
            $("#delete").on("click", function () {
                var ids = $.map($('#repairPlanTable').bootstrapTable('getSelections'), function (row) {
                    return row.pkId;
                });
                if (ids.length < 1) {
                    DialogUtil.warning("请选择需要删除的记录");
                    return false;
                }
                DialogUtil.ok_and_cancel("是否确定删除记录？", function () {
                    $.ajax({
                        url: ctx + '/equipment/repairPlan/logicDeleteRepairPlanByPkIds/del.mvc',
                        type: "post",
                        dataType: 'json',
                        data: {
                            pkIds: ids.toString()
                        },
                        success: function (response) {
                            if (response.result === true) {
                                DialogUtil.ok("删除成功");
                                $('#repairPlanTable').bootstrapTable('refresh');
                            } else {
                                DialogUtil.error(response.message);
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            DialogUtil.error(errorThrown);
                        }
                    });
                }, function () {

                });
            });
        },
        _modalHidden: function () {
            //模态框消失清空信息
            $("#myModal").on("hide.bs.modal", function () {
                $('#myModal').find('input').each(function () {
                    if ($(this).val() !== "") {
                        $(this).val("");
                    }
                });
                $(".maintenance-category").val("1");
                $("#dutyUserFormSelect2").val(null).trigger("change");
                $("#assistUserFormSelect2").val(null).trigger("change");
                $("#equipCode").val(null).trigger("change");
                $("#toolSelect2").val(null).trigger("change");
                $("#toolSelect2").find("option").remove();
                $("#partSelect2").val(null).trigger("change");
                $("#partSelect2").find("option").remove();
                $("#myModal").find("textarea").val("");
                $("#repairPlanForm").find("input:checkbox[name='shutdownFlag']").prop("checked", false);
                $("#repairPlanForm").find("input:checkbox[name='readyFlag']").prop("checked", false);
                $("#maintenanceCategory").val("");
                $('#repairPlanForm').bootstrapValidator('resetForm', false);
            });
        }
    }
}();